package com.xian.im.modules.command;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-01-27 09:55
 **/
@Slf4j
public class CommandContext {

    protected static Map<Integer,Command> CONTEXT_MAP = new ConcurrentHashMap<>();

    static {
        ServiceLoader<Command> loader = ServiceLoader.load(Command.class);
        for (Command command : loader) {
            CONTEXT_MAP.put(command.getCmd(),command);
        }
    }

    public static Command isMatch(Integer cmd){
        return CONTEXT_MAP.get(cmd);
    }

}
